<?php

namespace app\common\model\Order;

use think\Model;

// 软删除
use traits\model\SoftDelete;

class Refund extends Model{
    // 继承软删除
    use SoftDelete;

    //模型对应的是哪张表
    protected $table = "pre_refund";
    
    //开启自动写入
    protected $autoWriteTimestamp = true; 

    //设置字段的名字
    protected $createTime = 'createtime'; //插入的时候设置的字段名

    //禁止 写入的时间字段
    protected $updateTime = false;

    // 软删除的字段
    protected $deleteTime = 'deletetime';

    protected $append=[
        'status_text',
    ];
    protected function getStatusTextAttr($value,$data){
        $status=$data['status'];
        $text='';

        switch ($status) {
            case 0:
                $text='未确认';
                break;

            case 1:
                $text='已确认';
                break;
            case -1:
                $text='已拒绝';
                break;
            default:
                $text='未知状态';
        }
        return $text;
    }

    public function users(){
        return $this->belongsTo('app\common\model\User\User','userid','id',[],'LEFT')->setEagerlyType(1);
    }
}